/**   
 * @ClassName: ResultMapper.java 
 * @Package com.vrv.util 
 * @author LQ   
 * @date 2017年3月17日 上午1:23:01 
 * @version V1.0
 */
package com.vrv.common.util.result;

import java.util.HashMap;
import java.util.Map;

/** 
 * ResultMapper:返回数据
 * @author LQ 
 */
public class ResultMapper extends HashMap<String, Object> {

    private static final long serialVersionUID = 1L;
    
    public ResultMapper() {
        put("code", 0);
    }
    
    public static ResultMapper error() {
        return error(500, "未知异常，请联系管理员");
    }
    
    public static ResultMapper error(String msg) {
        return error(500, msg);
    }
    
    public static ResultMapper error(int code, String msg) {
        ResultMapper r = new ResultMapper();
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }
    

    public static ResultMapper ok(String msg) {
        ResultMapper r = new ResultMapper();
        r.put("msg", msg);
        return r;
    }
    
    public static ResultMapper ok(Map<String, Object> map) {
        ResultMapper r = new ResultMapper();
        r.putAll(map);
        return r;
    }
    
    public static ResultMapper ok() {
        return new ResultMapper();
    }

    public ResultMapper put(String key, Object value) {
        super.put(key, value);
        return this;
    }
    
}
